{% extends "base.html" %}
{% load i18n plmapp_tags %}

{% block scripts %}
    <script type="text/javascript" src="{{STATIC_URL}}js/jquery.showLoading.min.js"></script>
    <script type="text/javascript" src="{{STATIC_URL}}js/3D/ajax3D.js"></script>
{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{{STATIC_URL}}css/showLoading.css" type="text/css" media="screen" charset="utf-8" />
    <link rel="stylesheet" href="{{STATIC_URL}}css/displayDecompose.css" type="text/css"/>
{% endblock %}

{% block content %}

    <form method="post" action="" id="decompose_form"> {% csrf_token %} 

        <div style="display:none;">
            {{last_mtime}}
        </div>

        <div>
            <table class="Content">

                <thead>
                    <th>{% trans "Assembly" %}</th>
                    <th>{% trans "Child" %}</th>
                    <th>{% trans "Order" %}</th>
                    <th>{% trans "Quantity" %}</th>
                    <th>{% trans "Unit" %}</th>
                    <th>{% trans "Type" %}</th>
                    <th>{% trans "Name" %}  </th>
                    <th>{% trans "Reference" %} </th>
                    <th>{% trans "Revision" %} </th>
                    <th>&nbsp;</th>
                </thead>

                {% if extra_errors %}
                    <tr class="extra_errors">
                        <td class="errors" colspan="10">{{extra_errors}}</td>
                    </tr>
                {% endif %}
                {% for deep in deep_assemblies %} 


                    <tr class="assembly"> 
                        <td class="assembly_level{% if forloop.counter0 == 0 %} open {% endif %}" id="{{forloop.counter0}}" colspan="10">
                            <span class="display_level" title="{%trans "Display or Hide all assemblies at this level"%}">{% trans "Level" %} {{forloop.counter0}}</span>
                        </td>        

                    </tr>
                    {% with forloop.counter0 as level %}

                        {% for assembly in deep %}       <!-- assembly.0 froms ,  assembly.1 name , assembly.2 interne reference pour href links , assembly.4 type-->                  


                            <tr class="assembly"> 
                                <td class="assembly_name{% if level == 0 %} open {%endif %}" id="{{assembly.1}}" level="{{level}}{{forloop.counter0}}" colspan="10">
                                    <span class="display_name"> {{assembly.1}}

                                        <a id="{{assembly.2}}_part">
                                            <!--(Part) type de part de la part  -->
                                            ({{assembly.4}})
                                        </a>
                                    </span>
                                </td>
                            </tr> 


                            {% with forloop.counter0 as assembly_num %}

                                {% for part_type, ord_quantity, part_doc_cforms, name , is_assembly, prefix, ref  in assembly.0 %} 

                                    <tr class="part {% if level > 0 %} hidden{% endif %}" name="part{{level}}{{assembly_num}}{{forloop.counter0}}" level="{{level}}{{assembly_num}}{{forloop.counter0}}">


                                        <td class="|->">
                                            <!--esthetique -->
                                            {%if not prefix and forloop.last %}
                                                <img src="{{STATIC_URL}}img/arrows.png" alt="->" hight="50%" width="50%" />
                                            {% else %}

                                                {% if not forloop.last or forloop.first %} 
                                                    <img src="{{STATIC_URL}}img/arrow_middle.png" alt="|->" hight="50%" width="50%"/>
                                                {% else %}
                                                    <img src="{{STATIC_URL}}img/arrows.png" alt="->" hight="50%" width="50%"/>
                                                {% endif %}
                                            {% endif %}
                                            <!--/esthetique -->
                                        </td>

                                        <td>
                                            <p name="ref_{{name}}">
                                            {% if is_assembly %}

                                                <a class="display" href="#{{name}}" 
                                                    {% if ref %}
                                                        ref="#{{ref}}_ref"
                                                    {% endif %}
                                                    >{{name}}</a>
                                            {% else %}
                                                {{name}}   
                                            {% endif %}
                                            </p>

                                        </td>
                                        <td class="order">{{ord_quantity.order}}{{ord_quantity.order.errors }}</td>
                                        <td class="quantity">{{ord_quantity.quantity}}{{ord_quantity.quantity.errors}}</td>
                                        <td class="quantity">{{ord_quantity.unit}}{{ord_quantity.unit.errors}}</td>


                                        {% if prefix %} <!-- else the part was defined in a previous assembly , make a href -->
                                            <td class="cell_label part_type_form" id="{{prefix}}_ref">
                                                {{ part_type.type_part }}
                                            </td>

                                            {% for field in part_doc_cforms.0 %} 

                                                {% if field.name == "reference" or field.name == "name" or field.name == "revision" %}
                                                    <td class="{{field.errors|yesno:"errors,valid"}}">
                                                        <div style="max-width:100%"> {{  field }}</div> {{ field.errors }}
                                                    </td> 
                                                {% endif %}

                                            {% endfor %}

                                            <td>
                                                <button class="tb-btn toggle" id="part_show-{{prefix}}" >{{part_doc_cforms.0.errors|yesno:"-,+"}}</button> 
                                            </td>
                                        </tr>

                                        <tr class="part part_show-{{prefix}} show_hide" 
                                            {% if not part_doc_cforms.0.errors %} style="display:none;" {% endif %}
                                            >
                                            <td class="|">
                                                {% if not forloop.last %}
                                                    <img src="{{STATIC_URL}}img/line_part.png" alt="|" hight="50%" width="50%" />
                                                {% endif %}
                                            </td>
                                            <td class="vide" colspan="4">
                                            </td>
                                            <td colspan="5" id="extra_part_form-{{prefix}}"> 
                                                {% with part_doc_cforms.0 as creation_form %}
                                                    {% include "extra_attributes.html" %}
                                                {% endwith %}
                                            </td>

                                        {% else %} <!--  href for the part already defined-->

                                            <td colspan="5"> 
                                                <a class="indexed" href="#{{ref}}_ref" name="{{name}}">{% trans "already indexed" %}</a>
                                            </td>
                                        </tr>

                                    {% endif %}


                                    {% if prefix %} <!-- else nothing to show , the part was defined in a previous assembly  -->
                                        <tr class="document{% if level > 0 %} hidden {% endif %} "  name="doc{{level}}{{assembly_num}}{{forloop.counter0}}">
                                            <td class="|">
                                                {% if not forloop.last %}
                                                    <img src="{{STATIC_URL}}img/line.png" alt="|" hight="50%" width="50%"/>
                                                {% endif %}
                                            </td>
                                            <td class="vide" colspan="4">
                                            </td>


                                            <td class="cell_label">
                                                <p>Document3D</p>
                                            </td>

                                            {% for field in part_doc_cforms.1 %} 

                                                {% if field.name == "reference" or field.name == "name" or field.name == "revision" %}
                                                    <td class="{{field.errors|yesno:"errors,valid"}}">
                                                        {{  field }} {{ field.errors }}
                                                    </td> 
                                                {% endif %}

                                            {% endfor %}

                                            <td>
                                                <button class="tb-btn toggle" id="doc_show-{{prefix}}" >{{part_doc_cforms.1.errors|yesno:"-,+"}}</button> 
                                            </td>

                                        </tr> 

                                        <tr class="document doc_show-{{prefix}} show_hide" 
                                            {% if not part_doc_cforms.1.errors %} style="display:none;" {% endif %}
                                            >

                                            <td class="|">
                                                <!--esthetique -->
                                                {% if not forloop.last %}
                                                    <img src="{{STATIC_URL}}img/line.png" alt="|" hight="50%" width="50%"/>
                                                {% endif %}
                                                <!--/esthetique -->
                                            </td>

                                            <td class="vide" colspan="4">
                                            </td>
                                            <td colspan="5" id="extra_doc_form-{{prefix}}">
                                                {% with part_doc_cforms.1 as creation_form %}
                                                    {% include "extra_attributes.html" %}
                                                {% endwith %}
                                            </td>

                                        </tr> 

                                    {% endif %}             
                                {% endfor %}
                            {% endwith %}
                        {% endfor %}
                    {% endwith %}
                {% endfor %}
            </table>
        </div>
        <input class="tb-btn tb-btn-large tb-btn-primary" type="submit" value="{% trans "Create" %}"/> 

    </form>       


{% endblock %}


